package com.ruoyi.framework.shiro.realm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.ruoyi.framework.auth.service.SysLoginService;
import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.system.service.ISysRoleService;

/**
 * 自定义Realm 处理登录 权限
 * 
 * @author ruoyi
 */
public class UserRealm {
    private static final Logger log = LoggerFactory.getLogger(UserRealm.class);

    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private ISysRoleService roleService;

    @Autowired
    private SysLoginService loginService;

    /**
     * 授权
     */
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0)
//    {
//        SysUser user = ShiroUtils.getSysUser();
//        // 角色列表
//        Set<String> roles = new HashSet<String>();
//        // 功能列表
//        Set<String> menus = new HashSet<String>();
//        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//        // 管理员拥有所有权限
//        if (user.isAdmin())
//        {
//            info.addRole("admin");
//            info.addStringPermission("*:*:*");
//        }
//        else
//        {
//            roles = roleService.selectRoleKeys(user.getUserId());
//            menus = menuService.selectPermsByUserId(user.getUserId());
//            // 角色加入AuthorizationInfo认证对象
//            info.setRoles(roles);
//            // 权限加入AuthorizationInfo认证对象
//            info.setStringPermissions(menus);
//        }
//        return info;
//    }

}
